﻿using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Easy.Common;

namespace Easy.DAL
{
    public class PluginDAL
    {
        private readonly SqlDatabase sqldb = new SqlDatabase(Config.TulingBuyCrmConnectString);
        public DataTable getPluginTable()
        {
            string sqlCommand = string.Format(@"select * from plugin where DeletionStateCode = 0 order by entityName,priority desc");
            DbCommand cmd = sqldb.GetSqlStringCommand(sqlCommand);
            //SqlParameter[] param = { new SqlParameter("@UserId", UserId) };
            //cmd.Parameters.AddRange(param);
            DataTable dt = sqldb.ExecuteDataSet(cmd).Tables[0];
            return dt;
        }
        public void execSP(string spname, Guid currentrecord, Guid currentuser)
        {
            DbCommand cmd = sqldb.GetSqlStringCommand(spname);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@currentrecord", currentrecord));
            cmd.Parameters.Add(new SqlParameter("@currentuser", currentuser));
            sqldb.ExecuteNonQuery(cmd);
        }
    }
}
